package com.qf.servlet;

import com.qf.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author Ypl
 * @version V1.0
 * @Project September-mavens
 * @Package com.qf.servlet
 * @Description:
 * @Date 2022/10/8 20:51
 */
@SuppressWarnings("all")
@Controller
@RequestMapping("/test")
public class TestServlet {

    /**
     * get测试
     * @PathVariable("id") 在收取参数的时候的参数名称和前端传的参数的参数名不同时候用
     */
//    @GetMapping
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    @ResponseBody
    public User findById(@PathVariable("id") Integer uid){

        System.out.println("get :" + uid);
        User user = new User();
        user.setId(10);
        user.setName("lisi");
        user.setSex("女");
        user.setScore(100);
        return user;
    }

    /**
     * post测试
     */
//    @PostMapping
    @RequestMapping(value = "",method = RequestMethod.POST)
    @ResponseBody
    public String add(@RequestBody User user ){
        System.out.println("post : " + user);
        return "success";
    }

    /**
     * put请求
     */
//    PutMapping
    @RequestMapping(value = "",method = RequestMethod.PUT)
    @ResponseBody
    public String update(@RequestBody User user){
        System.out.println("put : "+user);
        return "success";
    }
    /**
     *delete 请求
     */
//    DeleteMapping
    @RequestMapping("/{id}")
    @ResponseBody
    public String delete( @PathVariable  Integer id){
        System.out.println("id =" + id);
        return "me success for delete";
    }
}
